require 'ctx_rbm'
require 'add_comp_rbm'
require 'add_vecosem_dbm'
require 'dict'


torch.setdefaulttensortype('torch.DoubleTensor')

function main()

	-- load dic & embs
	print('load dic & emb')
	local f = torch.DiskFile(dic_emb_path, 'r')
	dic 	= f:readObject()	setmetatable(dic, Dict_mt)
	wemb 	= f:readObject()
	f:close()

	-- load data
	print('load data')
	f = torch.DiskFile(data_path, 'r')
	f:binary()
	data = f:readObject():double()
	data = shuffle(data)
	f:close()

	-- load sampler storage
	print('load sampler storage')
	f = torch.DiskFile(sampler_storage_path, 'r')
	f:binary()
	sampler_storage = f:readObject()
	f:close()

	-- training
		print('training...')

		init_momentum = 0.9
		final_momentum = 0.9
		eps = 0.001
		weightcost = 0.0001
		chainlen = 300 
		nmarkovs = 100

		nepoch = 100
		batchsize = 100

		local comp_rbm = AddCompRBM:load_from_file('comp_model/1.model')
		local ctx_rbm = CtxRBM:load_from_file('ctx_model/3.model')
		local model = AddVeCoSemDBM:new(ctx_rbm, comp_rbm , wemb )
	
		print('training rbms...')
		model:train(data, nepoch, batchsize, init_momentum, final_momentum, 
					eps, weightcost, chainlen, nmarkovs, sampler_storage)
end

if #arg ~= 3 then
	print("<dic_emb_path> <data_path> <sampler_storage_path>")
else
	dic_emb_path			= arg[1]
	data_path				= arg[2]
	sampler_storage_path 	= arg[3]
	main()
end


